#!/bin/bash -e
# Execute all unittests with coverage and report code coverage.
#
# Copyright: Red Hat Inc.
# License: GPLv2
# Author: Lukas Doktor <ldoktor@redhat.com>

CANDIDATES="coverage3 coverage coverage2"
COVERAGE="$(which $CANDIDATES 2>/dev/null| head -n 1)"
if [ "x$COVERAGE" == "x" ]; then
    echo "No coverage utility found, looked for: $CANDIDATES"
    exit -1
fi
echo "Using coverage utilty: $COVERAGE"

$COVERAGE erase
rm -f .coverage.*
RUNNING_COVERAGE=1 AVOCADO_CHECK_LEVEL=1 UNITTEST_AVOCADO_CMD="$COVERAGE run -p --include 'avocado/*,optional_plugins/*' $PYTHON -m avocado" $COVERAGE run -p --include "avocado/*,optional_plugins/*" ./selftests/run
$COVERAGE combine .coverage*
echo
$COVERAGE report -m --include "avocado/core/*"
echo
$COVERAGE report -m --include "avocado/utils/*"
echo
$COVERAGE report -m --include "avocado/plugins/*"
echo
$COVERAGE report -m --include "optional_plugins/*"
$COVERAGE xml
